package Conexion;


import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;


import org.w3c.dom.*;

//import de.wurstgranulat.android.utils.xml.XmlUtil;
public class LoginXML {
	
	
	
	private Element root;
	private Document doc;

	
	public LoginXML(String usuario, String password) {
		try {
			DocumentBuilderFactory dbfac = DocumentBuilderFactory.newInstance();
			DocumentBuilder docBuilder;
			docBuilder = dbfac.newDocumentBuilder();
			doc = docBuilder.newDocument();
			root = doc.createElement("soapenv:Envelope");
			root.setAttribute("xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance");
			root.setAttribute("xmlns:xsd", "http://www.w3.org/2001/XMLSchema");
			root.setAttribute("xmlns:soapenv","http://schemas.xmlsoap.org/soap/envelope/");
			root.setAttribute("xmlns:wsdl","http://mercuriete.homeftp.org/moodle/wspp/wsdl");
			doc.appendChild(root);
			
			Element header = doc.createElement("soapenv:Header");
			root.appendChild(header);
			
		    Element login = doc.createElement("wsdl:login");
		    login.setAttribute("soapenv:encodingStyle","http://schemas.xmlsoap.org/soap/encoding/");
		  //  Element body = doc.getElement
			Element body = doc.createElement("soapenv:Body");
			root.appendChild(body);
		    body.appendChild(login);
		    
		    Element child = doc.createElement("username");
		    child.setAttribute("xsi:type", "xsd:string");
		    //child.setTextContent(usuario);  //el username
		    Node nodo = doc.createTextNode(usuario);
		    child.appendChild(nodo);
		    //child.setNodeValue(usuario);
		    login.appendChild(child);
		    child = doc.createElement("password");
		    child.setAttribute("xsi:type", "xsd:string");
		    //child.setTextContent(password);  //el password
		    nodo = doc.createTextNode(password);
		//    child.setNodeValue(password);
		    child.appendChild(nodo);
		    login.appendChild(child);
			
	
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();

		}
	}
	
	
	public String toString() {
	    try {
	   // 	String myString = XmlUtil.xmlDocumentToString(doc);
	  //  	return myString;
	    	return "";
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			return "";
		} 
	}
}
